package io.renren.modules.work.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.modules.work.service.ScExpenseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.work.entity.ScExpensedtlEntity;
import io.renren.modules.work.service.ScExpensedtlService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 报销细单
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-05-24 22:24:59
 */
@RestController
@RequestMapping("work/scexpensedtl")
public class ScExpensedtlController {
    @Autowired
    private ScExpensedtlService scExpensedtlService;

    @Autowired
    private ScExpenseService scExpenseService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = scExpensedtlService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{expendsedtlid}")
    public R info(@PathVariable("expendsedtlid") String expendsedtlid){
		ScExpensedtlEntity scExpensedtl = scExpensedtlService.getById(expendsedtlid);

        return R.ok().put("scExpensedtl", scExpensedtl);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ScExpensedtlEntity scExpensedtl){
        scExpensedtl.setCretime(new Date());
		scExpensedtlService.save(scExpensedtl);
        scExpensedtlService.caculate(scExpensedtl.getExpendseid());
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ScExpensedtlEntity scExpensedtl){
		scExpensedtlService.updateById(scExpensedtl);
        scExpensedtlService.caculate(scExpensedtl.getExpendseid());
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] expendsedtlids){
        String expendsedtlid = expendsedtlids[0];
        ScExpensedtlEntity scExpensedtlEntity = scExpensedtlService.getById(expendsedtlid);
        scExpensedtlService.removeByIds(Arrays.asList(expendsedtlids));
        scExpensedtlService.caculate(scExpensedtlEntity.getExpendseid());
        return R.ok();
    }



}
